package tech.aistar.corejava.day08.demo;

/**
 * Created by 李雨昂 on 2019/7/24.
 */
public class TestVehicle {
    public static void main(String[] args) {
        Vehicle car = new Car();
        Vehicle plane = new Plane();

        System.out.println(car instanceof ICheckSpeed);//true
        System.out.println(plane instanceof ICheckSpeed);//false

        Vehicle[] vehicles = new Vehicle[2];

        vehicles[0] = car;
        vehicles[1] = plane;

        //遍历数组
        for (Vehicle v : vehicles) {
            if(v instanceof ICheckSpeed) {
                if (v.getSpeed() > 100) {
                    System.out.println("超速!!!");
                } else {
                    System.out.println(v.getSpeed());
                }
            }else{
                System.out.println(v.getSpeed());
            }
        }
    }
}
